<template>
    <div class="p-15 p-t-0 box-shadow-1">
        <div class="table-search" >
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-input v-model="input" @keyup.enter.native="keyDown($event)" placeholder="请选择门店" :maxlength="20" size="medium"></el-input>
                </el-col>
                <el-col :span="6" class="text-left">
                    <el-button  class="btn-info"  icon="el-icon-search" @click="search" size="medium">搜索</el-button>
                    <el-button  class="btn-warning" style="margin-left: 1px"  icon="el-icon-refresh" @click="cleanSearch" size="medium">重置</el-button>
                </el-col>
            </el-row>
        </div>
        <div class="table-padding" >
            <div class="title-buttons">
            </div>
            <el-table
                     v-loading="loading"
                     :data="tableData"
                     border
                     style="width: 100%">
                <el-table-column
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        label="门店名称"
                        >
                    <template scope="scope">
                        <span>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="下发时间"
                        >
                    <template scope="scope">
                        <span v-if="scope.row.type">{{scope.row.type.text}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="支付类型"
                        >
                    <template scope="scope">
                      <span><el-button type="text" @click="isStoreNum=!isStoreNum;activityId=scope.row.id">{{scope.row.branchs}}</el-button></span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="支付名称"
                        >
                    <template scope="scope">
                       <span>{{scope.row.integral==true ? '是' :'否'}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="支付商户号">
                    <template scope="scope">
                        <span>{{scope.row.operateTime}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="备注">
                    <template scope="scope">
                        <span v-if="scope.row.state">{{scope.row.state.text}}</span>
                    </template>
                </el-table-column>
            </el-table>
            <br>
            <div class="block">
                <el-row>
                    <el-col :span="24" class="text-right">
                        <el-pagination
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="currentPage"
                                :page-sizes="pageSizeSet"
                                :page-size="pageSize"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="total">
                        </el-pagination>
                    </el-col>
                </el-row>
            </div>
        </div>
        <set-store :isShow="addShow" :id="activityId" v-on:close="addClose" v-on:addSuccess="addSuccess"></set-store>
      <storeNum :isShow="isStoreNum" :id="activityId" @close="addClose1" @addSuccess="addSuccess1"></storeNum>
        <PluginConfirm
                :show="dialogIsShow"
                @chooseSure="chooseSure()"
                @chooseCancel="chooseCancel()"
                @dialogResult="dialogResult">
        </PluginConfirm>
    </div>
</template>
<script>
    //注意路径
    import model from './model.vue'
    import setStore from './setStore.vue'
    import storeNum from './storeNum.vue'
    export default{
        data(){
            return {
                tableData: [],
                loading:false,
                pageSizeSet:window.pageSizes,
                pageSize:window.pageSize,
                currentPage:1,
                input:"",
                total:0,
                addShow:false,
                activityId:"",

                dialogIsShow:false,
                curDataRow:null,
                curDataIndex:0,
              multipleSelection:[],
              addStore:false,
              isStoreNum:false
            }
        },
        components: {
            model,
          setStore,
          storeNum
        },
        created(){
            window.this = this;
            this.initData();
        },
        methods: {
          updateState(id,item){
            var st='停用';
            if(item==1){
              st='停用';
            }else{
              st='启用';
            }
            this.$confirm('确定将状态改为'+st+', 是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.$axios.get("pays/payments/updateState?id="+id).then(data => {
                if(data.success){
                  this.$message({
                    type: 'success',
                    message: '修改成功'
                  });
                  this.initData();
                }else{
                  this.$message({
                    type: 'error',
                    message: data.message
                  });
                }

              })

            }).catch(() => {

            });

          },
          addStores(){
            if(this.multipleSelection.length<=0){
              this.$message.error("请选择服务费后操作");
              return;
            }
            this.addStore=true;this.activityId=''
          },
          handleSelectionChange(val) {
            this.multipleSelection = val;
            console.log(val);
          },
            initData(){
                this.loading=true;
                this.getData();
            },
            keyDown(ev){
                if(ev.keyCode==13) {
                  this.getData();
                }
            },
            search(){
              this.currentPage=1;
              this.inputValue="";
              if(this.input!="" && this.input!=undefined){
                this.inputValue="search.name_like="+this.input+"&"+this.inputValue;
              }
                    this.getData();
            },
            cleanSearch(){
                this.currentPage=1;
                this.input="";
                this.search();
            },
            handleCurrentChange(currentPage){
                 this.currentPage=currentPage;
                   this.getData();
            },
          getData(){
            this.$axios.get("pays/payments?"+this.inputValue+"&page.size="+this.pageSize+"&page.pn="+this.currentPage).then((data)=>{
              if(data.status==200){
                this.tableData=data.content.content;
                this.total=data.content.totalElements;
                this.loading=false
              }else{
                this.loading=false
              }
            })
          },
            goBack() {
                this.router.go(-1);
            },
            handleEdit(index, row) {
                console.log(index, row);
            },
            handleSizeChange(val){
                this.pageSize=val;
                this.search();
            },
            /*用户选择提示框后处理*/
            dialogResult(param){
                this.dialogIsShow=param.close;
                if(param.choose==="ok"){
                    //console.log("确定");
                  console.log(this.curDataRow);
                    this.$axios.delete("pays/payments/"+this.curDataRow.id).then(data=>{
                        if(data.status==200){
                            this.tableData.splice(this.curDataIndex,1);
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.initData();
                        }else{
                            this.$message({
                                type: 'error',
                                message: data.message
                            });
                        }
                    })
                }else if(param.choose==="cancel"){
                    //console.log("取消");
                }else{
                    //console.log("不做处理");
                }
            },
            handleDelete(index, row) {
                this.curDataIndex = index;
                this.curDataRow = row;
                this.dialogIsShow = true;
                return false;
            },
          addSuccess1(item){
            this.isStoreNum=false;
            this.currentPage=1;
            this.initData();
          },
          addClose1(){
            this.isStoreNum=false;
          },
            addSuccess(item){
               this.addShow=false;
               this.currentPage=1;
               this.initData();
            },
            addClose(){
                this.addShow=false;
            },
        }
    }
</script>
<style scoped>
</style>
